# coding=utf-8
# 全世界最帅的帅哥
from flask import Flask
from ysgg1_club_gateway.config.gateway_config import GatewayConfig
from ysgg1_club_gateway.nacos_register.register_server import register_server
from ysgg1_club_gateway.proxy_request import proxy_request
from ysgg1_club_gateway.utils.jwt_extended import jwt_extended


def create_app():
    app = Flask(__name__)
    app.config.from_object(GatewayConfig)

    # 配置日志
    from ysgg1_club_gateway.utils.gateway_logging import create_logger
    app.logger = create_logger(app)

    app.add_url_rule('/<service>/<path:remaining_path>/', endpoint="proxy_request", view_func=proxy_request,
                     methods=['GET', 'POST', 'PUT', 'DELETE'])

    register_server()

    jwt_extended.init_app(app)

    return app
